<template>
    <el-container>
                <el-main>
        <StElDynamicForm :helper-form="helperForm" :submit-props="{method: 'get',loading: searchLoading,onSubmit:(form,data)=>{queryParams = $stObjectTools.clone(data)}}"
                         :options="computedFormOptions" :origin-prop="{inline: true,labelWidth: '120px'}">
        </StElDynamicForm>
        <StElTable ref="steltable" :options="computedTableOptions" @loading="(val)=>{searchLoading = val}" :datas="computedUrl.searchList" :query-params="queryParams">
            <template #append>
                <el-table-column
                        label="操作"
                        width="200">
                    <template #default="{row,column,$index}">
                        <StElButtonGroup :group-param="{row,column,$index}" :operationMoreButtonOptions="{stype: 'link'}" :operations="tableOperations">
                        </StElButtonGroup>
                    </template>
                </el-table-column>

            </template>
        </StElTable>
        </el-main>
    </el-container>
</template>

<script>
    import ScheduleTriggerMixin from '../ScheduleTriggerMixin.js'

    export default {
        name: "ScheduleTriggerSearchList",
        mixins: [ScheduleTriggerMixin],
        props: {
        },
        computed: {
        },
        data() {
            return {
                queryParams: {},
                searchLoading:  false,

                helperForm: {
                },

                tableOperations: [
                    {
                        label: (groupParam) => {
                            if (!groupParam) {
                                return null
                            }
                            return  groupParam.groupParam.row.triggerState == 'PAUSED' ? '恢复': '暂停';
                        },
                        disabled: (groupParam) => {
                            if (!groupParam) {
                                return false
                            }
                            return  !(groupParam.groupParam.row.triggerState == 'PAUSED' || groupParam.groupParam.row.triggerState == 'NORMAL');
                        },
                        stype: 'link',
                        loading: false,
                        requestSuccess: ({groupParam}) => {
                            // 重新加载数据
                            this.$refs.steltable.reloadData()
                            this.$message.success('操作成功')
                        },
                        action: ({groupParam}) => {
                            return {
                                method: 'post',
                                url:  groupParam.row.triggerState == 'PAUSED' ?  this.computedUrl.resume : this.computedUrl.pause,
                                params: {name: groupParam.row.name,group: groupParam.row.group,schedulerName: this.$route.query.schedulerName || null,schedulerInstanceId: this.$route.query.schedulerInstanceId||null},
                                confirmText: `确定${groupParam.row.triggerState == 'PAUSED' ? '恢复': '暂停'} ${groupParam.row.name} 吗`
                            }
                        }
                    },
                ]
            }
        },
        methods: {
        }
    }
</script>

<style scoped>

</style>